package Tasks;

import Tools.Options;

public class MyRunnable implements Runnable{
	
	protected Object lock = null;
	protected boolean paused = false;

	public Object getLock() {
		return lock;
	}

	public void setLock(Object lock) {
		this.lock = lock;
	}
	
	protected void releaseLock()
	{
		if(getLock() != null)
		{
			synchronized(getLock())
			{
				getLock().notify();
			}
		}
	}
	
	public void placeLock()
	{
		if(getLock() != null)
		{
			synchronized(getLock())
			{
				try {
					getLock().wait();
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
	
	public synchronized void pause()
	{
		paused = true;
	}
	
	public synchronized void resume()
	{
		paused = false;
	}
	
	public synchronized boolean isPaused()
	{
		return paused;
	}
	
	public synchronized boolean isResumed()
	{
		return !paused;
	}
	
	protected boolean haltExecution()
	{
		return Options.PAUSE_SIMULATION || this.isPaused();
	}

	@Override
	public synchronized void run() 
	{
		
	}

}
